/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: SocketLoggerApp.java 229 2007-01-28 09:09:33Z jack.rybicki $
 */
package logmatcher.collectors;

import java.util.Scanner;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.apache.log4j.net.SocketAppender;

/**
 * Sends entered messages to a socket.
 *
 * @version $Revision: 229 $
 */
public class SocketLoggerApp {
    //~ Methods --------------------------------------------------------------------------------------------------------
	private static final Log LOGGER = LogFactory.getLog(SocketLoggerApp.class);
    /**
     * Start app, print out some invocation, collect input and send it to a socket.
     *
     * @param args command line arguments.
     */
    public static void main(String[] args) {
    	LOGGER.info("Starting application sending logs to a socket");
    	LOGGER.info("Enter empty line to stop the transmission");
    	SocketAppender app = new SocketAppender("localhost", 4560);
    	// Clean up log4j configuration
    	Logger.getRootLogger().addAppender(app);
    	String line=null;
    	Scanner scanner = new Scanner(System.in);
        do {
        	line = scanner.nextLine();
        	LOGGER.debug(line);
        } while (line.length()>0);
        scanner.close();
        app.close();
    }
}
